package com.interaction.qualitytimeaiagent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 向量数据库配置,基于内存的向量数据库
 */
@Configuration
public class QualitytimeVectorStoreConfig {

    @Resource
    private QualitytimeDocumentLoader documentLoader;
    @Resource
    private MyTokenTextSplitter splitter;
    @Resource
    private MyKeywordEnricher enricher;

    @Bean
    VectorStore qualityTimeVectorStore(EmbeddingModel dashscopeEmbeddingModel) {
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(dashscopeEmbeddingModel).build();
        List<Document> documents = documentLoader.loadQualitytimeDocuments();
//        List<Document> splitDocuments = splitter.splitDocuments(documents);
        List<Document> enrichDocuments = enricher.enrichDocuments(documents);
        simpleVectorStore.add(enrichDocuments);
        return simpleVectorStore;
    }
}
